package com.kuang.controller;

import com.kuang.pojo.AstManageDeviceRegister;
import com.kuang.pojo.AstUserCardActivate;
import com.kuang.service.asset.AstManageDeviceRegisterService;
import com.kuang.service.asset.AstUserCardActivateService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstUserCardActivateController {

    @Resource
    AstUserCardActivateService astUserCardActivateService;

    /**
     * 获取全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstUserCardActivates")
    public String getAstUserCardActivates(Model model){
        List<AstUserCardActivate> astUserCardActivates = astUserCardActivateService.selectAll();
        model.addAttribute("datas",astUserCardActivates);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "mqtt/ast_user_card_activate_list";
    }

    /**
     * 获取数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstUserCardActivatesByExample")
    public String getAstUserCardActivatesByExample(AstUserCardActivate astUserCardActivate,Model model){

        List<AstUserCardActivate> astUserCardActivates = astUserCardActivateService.selectAllByExample(astUserCardActivate);
        model.addAttribute("datas",astUserCardActivates);
        model.addAttribute("device_code",astUserCardActivate.getDevice_code());
        model.addAttribute("ver",astUserCardActivate.getVer());
        return "mqtt/ast_user_card_activate_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstUserCardActivatesById/{id}")
    public String getAstUserCardActivatesById(@PathVariable("id") String id, Model model){
        AstUserCardActivate astUserCardActivate = new AstUserCardActivate();
        astUserCardActivate.setAst_user_card_activate_id(id);
        List<AstUserCardActivate> astUserCardActivates = astUserCardActivateService.selectAllByExample(astUserCardActivate);
        model.addAttribute("data",astUserCardActivates.get(0));
        return "mqtt/ast_user_card_activate_from";
    }

}
